@echo off
setlocal

:: 获取用户的主目录
set USERDIR=%USERPROFILE%

:: 创建 .hashsum 文件夹
if not exist "%USERDIR%\.hashsum" mkdir "%USERDIR%\.hashsum"

:: 将 hashsum.exe 复制到 .hashsum 文件夹
copy hashsum.exe "%USERDIR%\.hashsum\hashsum.exe"

:: 添加右键菜单项到注册表
reg add "HKCU\Software\Classes\*\shell\hashsum" /v "MUIVerb" /t REG_SZ /d "HashSum" /f
reg add "HKCU\Software\Classes\*\shell\hashsum" /v "SubCommands" /t REG_SZ /d "" /f

:: 创建子命令项
reg add "HKCU\Software\Classes\*\shell\hashsum\shell" /f

:: 添加 MD5 子命令
reg add "HKCU\Software\Classes\*\shell\hashsum\shell\md5" /v "MUIVerb" /t REG_SZ /d "MD5 Hash" /f
reg add "HKCU\Software\Classes\*\shell\hashsum\shell\md5\command" /v "" /t REG_SZ /d "cmd.exe /k \"\"%USERDIR%\\.hashsum\\hashsum.exe\" \"%%1\" md5\"" /f

:: 添加 SHA1 子命令
reg add "HKCU\Software\Classes\*\shell\hashsum\shell\sha1" /v "MUIVerb" /t REG_SZ /d "SHA1 Hash" /f
reg add "HKCU\Software\Classes\*\shell\hashsum\shell\sha1\command" /v "" /t REG_SZ /d "cmd.exe /k \"\"%USERDIR%\\.hashsum\\hashsum.exe\" \"%%1\" sha1\"" /f

:: 添加 SHA256 子命令
reg add "HKCU\Software\Classes\*\shell\hashsum\shell\sha256" /v "MUIVerb" /t REG_SZ /d "SHA256 Hash" /f
reg add "HKCU\Software\Classes\*\shell\hashsum\shell\sha256\command" /v "" /t REG_SZ /d "cmd.exe /k \"\"%USERDIR%\\.hashsum\\hashsum.exe\" \"%%1\" sha256\"" /f

:: 添加 "全部" 子命令
reg add "HKCU\Software\Classes\*\shell\hashsum\shell\all" /v "MUIVerb" /t REG_SZ /d "All Hashes" /f
reg add "HKCU\Software\Classes\*\shell\hashsum\shell\all\command" /v "" /t REG_SZ /d "cmd.exe /k \"\"%USERDIR%\\.hashsum\\hashsum.exe\" \"%%1\" all\"" /f

echo Installation complete. You can now right-click files to calculate hashes (md5, sha1, sha256, all).
pause
